<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
	<title>01-引入对象</title>
	<style type="text/css">
	* {
		padding: 0;
		margin: 0;
	}
</style>
</head>
<body>
	<div class="container">
		<h1>01-引入对象</h1>
	</div>
	<script src="https://cdn.staticfile.org/jquery/3.2.0/jquery.js"></script>
	<script type="text/javascript">
		let name = '向军'
		let grade = [
		{ lesson: "js", score: 99 },
		{ lesson: "mysql", score: 85 }
		];

		function average(grade, name) {
			var total = grade.reduce((t,l) => t += l.score, 0)
			return name + ":" + total / grade.length + "分";
		}
		// 面向过程的写法
		console.log(average(grade, name))
		



		let user = {
			name : '向军',
			grade : [
				{ lesson: "js", score: 99 },
				{ lesson: "mysql", score: 85 }
			],
			average() {
				var total = grade.reduce((t,l) => t += l.score, 0)
				return this.name + ":" + total / this.grade.length + "分";
			}
		}
		// 面向对象的写法
		console.log(user.average())
		
	</script>
</body>
</html>